<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String contextPath = application.getContextPath();
	pageContext.setAttribute("path", contextPath);
%>
﻿<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<link rel="stylesheet" type="text/css" href="${path }/lib/layui/css/layui.css" />
<%-- <link rel="stylesheet" type="text/css" href="${path }/lib/common.css" /> --%>
<title>权限管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<form class="Huiform" method="post" action="" target="_self">
			<input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="" name="">
			<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜权限节点</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
	<span class="l">
		<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		<a href="javascript:;" onclick="permission_add('添加权限节点','${path}/user/toPage.do?page=admin-permission-add','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a>
		<a href="javascript:;" id="btn-expand" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe6e2;</i> 全部展开</a> 
		<a href="javascript:;" id="btn-fold" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe6e2;</i> 全部折叠</a> 
		<a href="javascript:;" id="btn-refresh" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe6e2;</i> 刷新</a> 
	</span> 
	<span class="r">共有数据：<strong id="totalRow">-</strong> 条</span> </div>
<!-- 	<table id="permTbl" class="table table-border table-bordered table-bg"> -->
<!-- 		<thead> -->
<!-- 			<tr> -->
<!-- 				<th scope="col" colspan="7">权限节点</th> -->
<!-- 			</tr> -->
<!-- 			<tr class="text-c"> -->
<!-- 				<th width="25"><input type="checkbox" name="" value=""></th> -->
<!-- 				<th width="40">序号</th> -->
<!-- 				<th width="200">权限名称</th> -->
<!-- 				<th>权限类型</th> -->
<!-- 				<th width="300">创建时间</th> -->
<!-- 				<th width="100">操作</th> -->
<!-- 			</tr> -->
<!-- 		</thead> -->
<!-- 		<tbody> -->
<!-- 		</tbody> -->
<!-- 	</table> -->
	<div class="layui-container layui-text">
		<table id="permTbl" class="layui-table table table-border table-bordered table-bg" lay-filter="table1"></table>
	</div>
</div>

<jsp:include page="_footer.jsp" flush="true"></jsp:include>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${path }/lib/layui/layui.js"></script>
<script type="text/javascript">

$(function(){
	
// 	initDg('permTbl', {
// 		queryUrl : '${path}/sysPermission/query.do',
// 		beforeAjax : function(data){
// 		},
// 		sucessAjax : function(result){
// 			$('#totalRow').html(result.data.recordsTotal);
// 		},
// 		columns: [
//             { "data": null },
//             { "data": null },
//             { "data": "name" },
//             { "data": "type" },
//             { "data": "createTime" },
//             { "data": null }
//         ],
//         rowCallback : function(row, data, index){
//         	$('td:eq(4)', row).html( fmtMillsec(data.createTime, true) );
//     		$('td:eq(5)', row).html( ' <a title="编辑" href="javascript:;" onclick="admin_role_edit(\'权限编辑\',\'${path}/user/toPage.do?page=admin-role-add\',\''+data.id+'\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_role_del(this,\''+data.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>' );
//         }
// 	});
	
	
	layui.config({
        base: '../lib/module/'
    }).extend({
        treetable: 'treetable-lay/treetable'
    }).use(['layer', 'table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var treetable = layui.treetable;

        // 渲染表格
        var renderTable = function () {
            layer.load(2);
            treetable.render({
                treeColIndex: 1,
                treeSpid: 0,
                treeIdName: 'id',
                treePidName: 'pid',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#permTbl',
                url: '../sysPermission/queryTree.do',
                page: false,
                cols: [[
                    {type: 'numbers'},
                    {field: 'name', title: '权限名称'},
                    {field: 'type', title: '权限类型', templet: function(o){
                    	return o.type == null ? '' : o.type == 0 ? '页面' : '功能';
                    }},
                    {field: 'createTime', title: '创建时间', templet: function(o){
                    	return fmtMillsec(o.createTime);
                    }},
                    {field: 'updateTime', title: '修改时间', templet: function(o){
                    	return fmtMillsec(o.updateTime);
                    }},
                    {title: '操作', templet: function(o){
                    	return '<a title="编辑" href="javascript:;" onclick="permission_edit(\'权限编辑\',\'${path}/user/toPage.do?page=admin-permission-add\',\''+o.id+'\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="permission_del(this,\''+o.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                    }}
                ]],
                done: function (data) {
                    layer.closeAll('loading');
                    $('#totalRow').text(data.data.length);
                }
            });
        };

        renderTable();

        $('#btn-expand').click(function () {
            treetable.expandAll('#permTbl');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#permTbl');
        });

        $('#btn-refresh').click(function () {
            renderTable();
        });

        //监听工具条
        table.on('tool(permTbl)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'del') {
                layer.msg('删除' + data.id);
            } else if (layEvent === 'edit') {
                layer.msg('修改' + data.id);
            }
        });
    }); 
	
});

/**
 * 子页面调用父页面该方法
 */
function refresh(index){
	queryUser();
	layer.close(index);
}

/**
 * 触发dataTable的查询
 */
function queryUser(){
// 	$("#permTbl").dataTable().fnDraw(false);
	$('#btn-refresh').click();
}


/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*管理员-权限-添加*/
function permission_add(title,url,w,h){
	w = 800;
	h = $(window).height() - 50;
	layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
		success: function(layero, index){
		    var body = layer.getChildFrame('body', index);
		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		    iframeWin.initPermsData();
	    }
	});
}
/*管理员-权限-编辑*/
function permission_edit(title,url,id,w,h){
	w = 800;
	h = $(window).height() - 50;
	layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
		success: function(layero, index){
		    var body = layer.getChildFrame('body', index);
		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		    iframeWin.fillData(id);
	    }
	});
}

/*管理员-权限-删除*/
function permission_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '../sysPermission/delete.do',
			data:'ids='+id,
			dataType: 'json',
			success: function(data){
				if (data.code == 0) {
					layer.msg('已删除!',{icon:1,time:1000});
					window.setTimeout(function(){
						$('#btn-refresh').click();
					}, 1000);
				} else {
					alert('系统错误！');
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script>
</body>
</html>
